package com.cnsugar.ai.face;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import java.util.LinkedList;
import java.util.List;

/**
 * @Author ChenZhangKun
 * @Date 2020/4/24 10:33
 */
public class LoadLibrary implements Runnable {
    private static final Logger logger = LoggerFactory.getLogger(LoadLibrary.class);
    private static volatile String[] libs;
    private static volatile List<String> list=new LinkedList<>();
    public static volatile LoadStatus loadStatus = LoadStatus.READY;

    public LoadLibrary(String[] libs) {
        LoadLibrary.libs = libs;
        turnList();
    }

    public enum LoadStatus {
        READY, LOADING, FINISH
    }
    public static List<String> turnList(){
        for (String lib : libs) {
            list.add(lib);
        }
        return list;
    }
    @Override
    public void run() {
        LoadLibrary.loadStatus=LoadStatus.LOADING;
        while (list.size()!=0){
            synchronized (LoadLibrary.class){
                if (list.size()!=0) {
                    logger.debug(Thread.currentThread().getName() + "  new Thread load library: {}", list.get(0));
                    System.loadLibrary(list.get(0));
                    list.remove(0);
                }
            }
        }
        LoadLibrary.loadStatus=LoadStatus.FINISH;
    }
    public static LoadStatus getLoadStatus(){
        return loadStatus;
    }
}

